import { _decorator, Color, Component, Label, Node, Sprite, SubContextView } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('UIRankTabControl')
export class UIRankTabControl extends Component {
    
    @property({ type: [Node], tooltip: '页面切换按钮' })
    btns: Node[] = [];
    
    @property({ type: [Node], tooltip: '页面' })
    pages: Node[] = [];
    
    @property({ type: [Color], tooltip: '选中/非选中颜色' })
    colors: Color[] = [];
    
    @property({ type: Sprite, tooltip: '切换按钮背景图' })
    spHighlight: Sprite = null;

    private nowPage: number = 0;

    onBtnClick(event: TouchEvent, page: number) {

        if (page == this.nowPage) return;

        const lbTitlePre = this.btns[this.nowPage].getChildByName('title').getComponent(Label);
        lbTitlePre.color = this.colors[0];

        const lbTitleNow = this.btns[page].getChildByName('title').getComponent(Label);
        lbTitleNow.color = this.colors[1];
        const posNow = this.btns[page].getPosition();
        this.spHighlight.node.setPosition(posNow);

        this.pages.forEach((node, i) => node.active = i == page);

        this.nowPage = page;

        // 好友排行榜子域展示
        this.pages[1].getComponent(SubContextView).enabled = this.nowPage == 1;


    }





}

